/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaceNewOrder_Home.java
 *
 * Created on Oct 2, 2014, 4:03:29 PM
 */
package com.JD.Test;

import com.JD.datePicker.DatePicker;
import com.JD.master.Hibernate.PartyMaster;
import com.JD.master.Validation.Validator;
import java.util.*;
import javax.swing.JPanel;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 *
 * @author admin
 */
public class PlaceNewOrder_Home extends javax.swing.JFrame {

    /** Creates new form PlaceNewOrder_Home */
    com.JD.master.Validation.Validator validator = new Validator();
    String party_Name = "NO";
    String party_Adrres = "NO";
    String party_City = "NO";
    String party_Phone = "NO";
    String party_Website = "NO";
    String rawField1 = "NO";
    String rawField2 = "NO";
    String rawField3 = "NO";
    String rawField4 = "NO";

    public PlaceNewOrder_Home() {
        initComponents();


        com.JD.datePicker.DatePicker datePicker = new DatePicker();
        List year_List = datePicker.getYear_List();
        List day_List = datePicker.getDay_List();


        for (Object object : year_List) {

            year_Combobox.addItem(object.toString());
        }

        for (Object object : day_List) {

            date_ComboBox.addItem(object.toString());

        }

        String month[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

        

        month_Combobox.addItem(month[Integer.parseInt(new java.text.SimpleDateFormat("MM").format(new Date()))-1]);

        for (String string : month) {

            month_Combobox.addItem(string);
        }




    }

    public JPanel getAddNewParty_Panel() {
        return AddNewParty_Panel;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        AddNewParty_Panel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        partyName_TextField = new javax.swing.JTextField();
        phone_TextField = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        address_TextField = new javax.swing.JTextArea();
        jLabel5 = new javax.swing.JLabel();
        city_TextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        website_TextField = new javax.swing.JTextField();
        addDataToDatabase = new javax.swing.JButton();
        resetButton = new javax.swing.JButton();
        year_Combobox = new javax.swing.JComboBox();
        month_Combobox = new javax.swing.JComboBox();
        date_ComboBox = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        partyTable = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        AddNewParty_Panel.setBackground(new java.awt.Color(255, 102, 51));
        AddNewParty_Panel.setPreferredSize(new java.awt.Dimension(1135, 627));

        jLabel1.setFont(new java.awt.Font("Traditional Arabic", 1, 24));
        jLabel1.setForeground(new java.awt.Color(18, 68, 200));
        jLabel1.setText("ADD PARTY DETAILS");

        jLabel2.setBackground(java.awt.Color.white);
        jLabel2.setFont(new java.awt.Font("Traditional Arabic", 1, 18));
        jLabel2.setForeground(new java.awt.Color(18, 68, 200));
        jLabel2.setText("Party Name:");

        jLabel3.setBackground(java.awt.Color.white);
        jLabel3.setFont(new java.awt.Font("Traditional Arabic", 1, 18));
        jLabel3.setForeground(new java.awt.Color(18, 68, 200));
        jLabel3.setText("Address:");

        jLabel4.setBackground(java.awt.Color.white);
        jLabel4.setFont(new java.awt.Font("Traditional Arabic", 1, 18));
        jLabel4.setForeground(new java.awt.Color(18, 68, 200));
        jLabel4.setText("Phone:");

        partyName_TextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                partyName_TextFieldActionPerformed(evt);
            }
        });
        partyName_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                partyName_TextFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                partyName_TextFieldKeyReleased(evt);
            }
        });

        phone_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                phone_TextFieldKeyReleased(evt);
            }
        });

        address_TextField.setColumns(20);
        address_TextField.setRows(5);
        address_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                address_TextFieldKeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(address_TextField);

        jLabel5.setBackground(java.awt.Color.white);
        jLabel5.setFont(new java.awt.Font("Traditional Arabic", 1, 18));
        jLabel5.setForeground(new java.awt.Color(18, 68, 200));
        jLabel5.setText("City:");

        city_TextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                city_TextFieldActionPerformed(evt);
            }
        });
        city_TextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                city_TextFieldKeyReleased(evt);
            }
        });

        jLabel6.setBackground(java.awt.Color.white);
        jLabel6.setFont(new java.awt.Font("Traditional Arabic", 1, 18));
        jLabel6.setForeground(new java.awt.Color(18, 68, 200));
        jLabel6.setText("Email:");

        addDataToDatabase.setFont(new java.awt.Font("Traditional Arabic", 0, 18));
        addDataToDatabase.setText("Add Data");
        addDataToDatabase.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addDataToDatabaseMouseClicked(evt);
            }
        });
        addDataToDatabase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDataToDatabaseActionPerformed(evt);
            }
        });

        resetButton.setFont(new java.awt.Font("Traditional Arabic", 0, 18));
        resetButton.setText("Reset");

        year_Combobox.setEditable(true);

        month_Combobox.setEditable(true);

        date_ComboBox.setEditable(true);

        partyTable.setFont(new java.awt.Font("Traditional Arabic", 0, 14));
        partyTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Party Name", "Phone", "Address", "City", "Email"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(partyTable);

        javax.swing.GroupLayout AddNewParty_PanelLayout = new javax.swing.GroupLayout(AddNewParty_Panel);
        AddNewParty_Panel.setLayout(AddNewParty_PanelLayout);
        AddNewParty_PanelLayout.setHorizontalGroup(
            AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1050, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(125, Short.MAX_VALUE))
            .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                .addGap(437, 437, 437)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(458, Short.MAX_VALUE))
            .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                .addGap(234, 234, 234)
                .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                        .addComponent(addDataToDatabase)
                        .addGap(40, 40, 40)
                        .addComponent(resetButton, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                        .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AddNewParty_PanelLayout.createSequentialGroup()
                                .addComponent(year_Combobox, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(40, 40, 40)
                                .addComponent(month_Combobox, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                                .addComponent(date_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(website_TextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 411, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AddNewParty_PanelLayout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                                .addComponent(city_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(phone_TextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 411, Short.MAX_VALUE)
                            .addComponent(partyName_TextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(414, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        AddNewParty_PanelLayout.setVerticalGroup(
            AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, AddNewParty_PanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(partyName_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(phone_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE))
                .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(city_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(website_TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(date_ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(month_Combobox, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(AddNewParty_PanelLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(year_Combobox, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(37, 37, 37)
                .addGroup(AddNewParty_PanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addDataToDatabase)
                    .addComponent(resetButton))
                .addGap(35, 35, 35)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(AddNewParty_Panel, javax.swing.GroupLayout.DEFAULT_SIZE, 1175, Short.MAX_VALUE)
                .addGap(20, 20, 20))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(AddNewParty_Panel, javax.swing.GroupLayout.PREFERRED_SIZE, 718, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void city_TextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_city_TextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_city_TextFieldActionPerformed

    private void addDataToDatabaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDataToDatabaseActionPerformed
        // TODO add your handling code h

        SessionFactory sessionFactory = com.JD.master.Hibernate.Master_HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        Transaction transaction = session.beginTransaction();

        party_Name = partyName_TextField.getText();
        party_Adrres = address_TextField.getText();
        party_City = city_TextField.getText();
        party_Phone = phone_TextField.getText();
        party_Website = website_TextField.getText();

        com.JD.master.Hibernate.PartyMaster partyMaster = new PartyMaster(party_Name, party_Adrres, party_City, party_Phone, party_Website, rawField1, rawField2, rawField3, rawField4);

        session.save(partyMaster);
        transaction.commit();

        javax.swing.table.DefaultTableModel model = (javax.swing.table.DefaultTableModel) partyTable.getModel();

        model.insertRow(0, new Object[]{party_Name, party_Phone, party_Adrres, party_City, party_Website});

        partyName_TextField.setText("");
        address_TextField.setText("");
        city_TextField.setText("");
        phone_TextField.setText("");
        website_TextField.setText("");

    }//GEN-LAST:event_addDataToDatabaseActionPerformed

    private void addDataToDatabaseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addDataToDatabaseMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_addDataToDatabaseMouseClicked

    private void partyName_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_partyName_TextFieldKeyReleased
        // TODO add your handling code here:

        partyName_TextField.setText(validator.stringValidator(partyName_TextField.getText()).toUpperCase());



    }//GEN-LAST:event_partyName_TextFieldKeyReleased

    private void partyName_TextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_partyName_TextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_partyName_TextFieldActionPerformed

    private void partyName_TextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_partyName_TextFieldKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_partyName_TextFieldKeyPressed

    private void phone_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_phone_TextFieldKeyReleased
        // TODO add your handling code here:

        phone_TextField.setText(validator.numberValidator(phone_TextField.getText().toUpperCase()));

    }//GEN-LAST:event_phone_TextFieldKeyReleased

    private void city_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_city_TextFieldKeyReleased
        // TODO add your handling code here:

        city_TextField.setText(validator.stringValidator(city_TextField.getText()).toUpperCase());
    }//GEN-LAST:event_city_TextFieldKeyReleased

    private void address_TextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_address_TextFieldKeyReleased
        // TODO add your handling code here:


        address_TextField.setText(address_TextField.getText().toUpperCase());
    }//GEN-LAST:event_address_TextFieldKeyReleased
    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JPanel AddNewParty_Panel;
    private javax.swing.JButton addDataToDatabase;
    private javax.swing.JTextArea address_TextField;
    private javax.swing.JTextField city_TextField;
    private javax.swing.JComboBox date_ComboBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JComboBox month_Combobox;
    private javax.swing.JTextField partyName_TextField;
    private javax.swing.JTable partyTable;
    private javax.swing.JTextField phone_TextField;
    private javax.swing.JButton resetButton;
    private javax.swing.JTextField website_TextField;
    private javax.swing.JComboBox year_Combobox;
    // End of variables declaration//GEN-END:variables
}
